perf(stake): cache + multicall the orbit graph; fix stale dialog copy - #196
Merged
Conversation
The orbit did dozens of sequential client RPC round-trips on every mount (per-backer balanceOf + convertToAssets in a loop, per-pool log scans), so it painted slowly. Move it server-side and cache it: - New /api/stake-graph (revalidate 60s + stale-while-revalidate 300s), backed by src/services/stake-graph.ts. Shared across users → warm loads are instant. - Multicall3: each vault's totalAssets/totalSupply/every balance goes in ONE aggregated call; shares→assets is computed locally, dropping all per-backer convertToAssets calls. MOR log scans + usersData reads are parallelized and multicalled too. - useStakeGraph is now a thin react-query hook over the cached route (kept warm between navigations); same public API and types. Also fixes wrong dialog copy: the disclaimer no longer claims staking "isn't wired to a contract yet" (it is), and the intro no longer says "Stake ETH". Localized en + pt-br. Multicall verified against a live vault; tsc + next build clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why the orbit was slow
useStakeGraphdid the whole thing client-side on every mount: per rider vault it fetched backers, then in a sequential loop readbalanceOf+convertToAssetsfor each backer (2 RPC round-trips each), plus per-pool MOR log scans and per-userusersDatareads. Dozens of serial round-trips → slow paint.Smart tricks
GET /api/stake-graph(revalidate 60s+stale-while-revalidate 300s). The graph is user-independent, so it's shared across all users — warm loads are instant JSON.totalAssets/totalSupply/ everybalanceOfgoes in one aggregated call; shares→assets is computed locally (shares * totalAssets / totalSupply), which deletes all per-backerconvertToAssetscalls. The MOR log scan (chunks) andusersDatareads are parallelized and multicalled.useStakeGraph(nonce)→StakeGraph | null).Net: cold compute collapses from ~2·N + scan round-trips to a handful; repeat/other-user loads hit cache.
Also: fixed wrong dialog copy
Multicall verified against a live vault (totalAssets/totalSupply/balance in one call).
tsc+next buildclean.🤖 Generated with Claude Code